package com.pn.controller;

import com.pn.entity.SysUser;
import com.pn.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/sys/user")
@RestController
public class SysUserController {

    //注入SysUserService
    @Autowired
    private SysUserService userService;

    /*
      查询当前登录的用户的url接口/sys/user/info
     */
    @RequestMapping("/info")
    public ResponseEntity<SysUser> queryUserInfo(){

        //拿到当前登录的用户id
        String userId = SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString();

        //执行业务
        SysUser sysUser = userService.getById(userId);

        //响应
        return ResponseEntity.ok(sysUser);
    }
}
